Setting Object Properties

Description

Scripts can be attached to object events, listed in the object's properties.

Some of the examples in this guide require the "Learning Action Scripting" workspace. See Creating Your First Action Script to learn how to get the "Learning Action Scripting" workspace installed.

In this example, we will show you how you can attach scripts to some of the other object events. We will change the appearance of a field label when the corresponding field gets focus. This will highlight the use of the OnArrive and OnDepart events.

To begin the example:

  1. Select the Tables tab on the Control Panel.

  2. Right-click the "Receipts" table and select Open Default Form.

    images/Object_Properties_1.gif
  3. Click the Design button on the toolbar to switch to Design Mode.

    • Currently all the field labels are bold. We'll start by turning bold off for these labels.

    images/object_properties_2.gif
  4. Click on the Customer Id field. Depending on your settings, both the field and its corresponding label may be grouped. In this case both objects will be selected. Since we want to change the property of the Customer Id field's label, click a second time on the Customer Id label. The size handles on the label should be dark, while the size handles on the field should be light (as shown below).

    images/object_properties_3.gif
    If the field and its label are not grouped, then you can simply click on the Customer Id label.
  5. Right-click Customer Id and select Properties.

  6. Select the Font tab.

  7. Clear Bold.

  8. Click OK.

    images/object_properties_4.gif
  9. Right-click on the field label again.

  10. Select Copy appearance from the menu. This copies the appearance properties of the field label to the clipboard.

  11. Right-click the field label again, and select Paste all.

  12. Alpha Anywhere asks whether you want to paste the appearance to all Text objects on the form. Select OK. Your form should now look like this:

    images/object_properties_7.gif
  13. Now we will attach a script to the OnArrive event for the Amount field. Select the Amount field. (You may have to click the Amount field twice if it's grouped with the Amount label.)

    images/object_properties_8.gif
  14. Right-click and select Events > OnArrive.

    • The Code Editor appears. Make note of the tab label. "Untitled" is the name of the current form, which is called "Untitled" because we haven't saved it. "Amount" is the name of the current object on the form, and "OnArrive" is the name of the event.

      images/object_properties_10.gif
    images/object_properties_9.gif
  15. Click Add New Action.

  16. Select the "Object Properties" category, and the "Set Font of Object(s)" Action.

  17. Click OK. The Set Font of Object(s) Genie appears. This screen allows you to set the font properties of one or more objects on a form or browse window. You want to operate on the current form, so leave the selection in the first list box as is.

  18. You need to tell Alpha Anywhere which object on the form we want to manipulate. Click the green '+' button for Set ?Font' properties of the following objects text box. A list box of all the objects on the current form appears. Note that the icon to the left of each object indicates the object type.

    images/object_properties_13.gif
  19. Select "Amount_lbl". Alpha Anywhere automatically assigned this name to the Amount field label. Your screen should look like this:

    images/object_properties_14.gif
  20. Next you need to specify which font properties to set. Click the second green '+' button. A dialog box appears displaying which font properties are available for editing.

    images/object_properties_15.gif
  21. Select "font.bold", "font.underline", and "font.color". Your screen should now look like this:

    • For each property you select you have the option of setting the value to:

      • a constant value
      • a value contained in a variable
      • a value that is the result of an expression
    images/object_properties_16.gif
  22. You want to explicitly set the properties now, so select the first option, "Specify the value now".

  23. Set the "font.bold" property to "True". Now the field label will be bold when the Amount field gets focus.

    images/object_properties_17.gif
  24. Set "font.underline" to "True".

    images/object_properties_18.gif
  25. Set "font.color" to "Light Blue".

    images/object_properties_19.gif
  26. Click Next > and Finish to complete the Action. The Code Editor should now look like this:

    images/object_properties_20.gif
  27. The asterisk next to the script name indicates that we haven't saved the script. Click the Save button. The asterisk disappears because the script has been saved.

    • The script is saved in the form, but since the form itself has not yet been saved, if we closed the form without saving it, the script would be lost. This is a very important point to remember.
    • Now you need to define the OnDepart event for the field. If you did not define an OnDepart event to set the field label back to its original appearance, the field label would change to "blue, underline, bold" when Amount got focus, but would never change back to "black, no underline, normal" when the field lost focus.

      To begin defining the OnDepart event, you have two choices. You can either right click on the Amount field again and select Events > OnDepart, or you can click the Select Object? button in the Code Editor. Since you already know how to use the first approach, try the second one here.

  28. Click the Select Object? button.

  29. A list of objects on the form appears. Note that the "Amount_Lbl" object is bold because it's the only object that has events assigned to it.

  30. Select "Amount_Lbl".

    images/object_properties_21.gif
  31. Click the Select Event? button. A list of events for the Amount object appears. Note that only the "OnArrive" event is shown in bold because it's the only event that's been assigned a script.

    images/object_properties_22.gif
  32. Select the "OnDepart" event. Alpha Anywhere opens a new tab in the Code Editor :

    images/object_properties_23.gif
  33. Using the same steps you just followed, select the "Set Font of Object(s)" Action.

  34. Select the "Amount_lbl" object.

  35. Select "font.bold", "font.underline", and "font.color".

  36. Set "False" for "font.bold", "False" for "font.underline", and "Wintext" for "font.color". Your screen should look like this:

    images/object_properties_24.gif
  37. Click Next > and Finish to complete the Action.

  38. Click the Save button to save the script.

  39. Click on the form.

  40. Save the form, specifying any name you want.

  41. Click the Form View button to run the form.

  42. Tab into the Amount field, taking note of how the field label changes.

  43. Tab out of the field, taking note of how the field label changes back to its original settings.

    images/object_properties_26.gif

While the utility of this script may be limited, the principle is powerful. Action Scripts give you an easy way to manipulate practically any property on a form or browse window, letting you create highly customized user interfaces.

Limitations

Desktop Applications Only